<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>通过className获取元素</title>
</head>
<body>
    <div class="hd hdms xia"></div>
    <div class="hdms"></div>
    <script>
        // 可以用于其他节点，不限于document
        // const tags = document.body.getElementsByClassName('hdms hd');
        // console.log(tags);

        // 手写getElementByClassName
        function getByClassName(names){
            const classNames = names.toUpperCase().split(/\s+/).filter(v => v);
            return Array.from(document.getElementsByTagName('*')).filter(tag => {
                const tagNames = tag.className.toUpperCase().split(/\s+/).filter(v => v);
                return classNames.every(className => {
                   return tagNames.some(tagName => {
                       return tagName == className;
                    })
                })
            });
        }
        console.log(getByClassName('hdms hd'));
    </script>
</body>
</html>